package com.hiwhitley.chapter05;

/**
 * Created by hiwhitley on 17-1-12.
 */
public class Deformation {
    public static boolean isDeformation(String str1, String str2) {
        if (str1 == null || str2 == null || str1.length() != str2.length()) {
            return false;
        }

        char[] chars1 = str1.toCharArray();
        char[] chars2 = str2.toCharArray();

        int[] map = new int[256];
        for (int i = 0; i < chars1.length; i++) {
            map[chars1[i]]++;
        }

        for (int i = 0; i < chars2.length; i++) {
            if (map[chars2[i]]-- == 0)
                return false;
        }
        return true;
    }

    public static void main(String[] args) {
        System.out.println(isDeformation("1", "aab"));
    }
}
